<template>
	<view class="">
		<Header title="申请提现" :isHome="true" :isWhite='true'></Header>
		<view class="main">
			<view class="title">
				提现金额
			</view>
			<view class="money">
				<view>￥</view><input type="number" v-model="moneyValue" />
			</view>
			<view class="canwithdrawAll">
				<view class="canwithdraw">
					<span style="margin-right: 10rpx;">当前可提现金额</span><span>{{money}}</span><span>元</span>
				</view>
				<view class="withdrawal" @click="withdrawal">
					全部提现
				</view>
			</view>
		</view>
		<view class="tips">
			<view class="">
				<rich-text :nodes="text"></rich-text>
			</view>
		</view>
		<view class="btnAll">
			<!-- 禁用的按钮 -->
			<view class="confirmBtnDis" v-if="moneyValue==''">
				确认提现
			</view>
			<!-- 可点击的按钮 -->
			<view class="confirmBtn" v-else @click="addWithdrawals">
				确认提现
			</view>
		</view>
	</view>
</template>

<script>
	import {
		get,
		post
	} from '../../utils/request'
	export default {
		data() {
			return {
				money: '1223.00',
				moneyValue: '',
				text:''
			}
		},
		onLoad() {
			this.getMoney()
			this.getMoneyText()
		},
		methods: {
			// 获取可提现金额
			getMoney() {
				get('/user/get_withdrawable')
					.then(res => {
						this.money = res.data
					})
					.catch(err => {
						console.error('GET 请求失败:', err);
					});
			},
			// 获取可提现文案
			getMoneyText() {
				get('/system/withdrawal_text')
					.then(res => {
						this.text = res.data
					})
					.catch(err => {
						console.error('GET 请求失败:', err);
					});
			},
			addWithdrawals() {
				post('/user/add_withdrawals', {
						money: this.moneyValue
					}).then(res => {
						if (res.code == 1) {
							uni.showToast({
								title: res.msg
							})
							// this.money = Number(this.money) - Number(this.moneyValue)
							this.moneyValue = ''
							this.getMoney()
						}else{
							uni.showToast({
								title: res.msg,
								icon:'error'
							})
						}
					})
					.catch(err => {
						console.error('GET 请求失败:', err);
					});
			},
			withdrawal() {
				this.moneyValue = this.money
			}
		}
	}
</script>

<style lang="scss" scoped>
	.main {
		background: #fff;
		padding: 40rpx;

		.title {
			font-family: PingFangSC-Regular;
			font-weight: 400;
			font-size: 28rpx;
			color: #222222;
		}

		.money {
			display: flex;
			align-items: center;
			border-bottom: 1rpx solid #f5f5f5;

			view {
				font-family: PingFangSC-SNaNrpxibold;
				font-weight: 600;
				font-size: 48rpx;
				color: #222222;
				margin-right: 20rpx;
			}

			input {
				height: 130rpx;
				font-family: Bebas;
				font-size: 72rpx;
				font-weight: 600;
				color: #222222;
			}
		}

		.canwithdrawAll {
			display: flex;
			align-items: center;
			margin-top: 21rpx;
			color: #999999;
			font-size: 24rpx;
			font-family: PingFangSC;
			font-weight: 400;

			.withdrawal {
				color: #1a1a1a;
				margin-left: 10rpx;
			}
		}
	}

	.tips {
		padding: 32rpx;
		font-family: PingFangSC-Regular;
		font-weight: 400;
		font-size: 24rpx;
		color: #999999;
		line-height: 34rpx;
	}

	.btnAll {
		background-color: #FFFFFF;
		position: fixed;
		bottom: 0;
		width: 100%;
		height: 200rpx;
		box-sizing: border-box;
		padding: 20rpx 0 50rpx;

		view {
			width: 670rpx;
			height: 96rpx;
			border-radius: 48rpx;
			font-family: PingFangSC-SNaNrpxibold;
			font-weight: 600;
			font-size: 32rpx;
			color: #FFFFFF;
			text-align: center;
			line-height: 96rpx;
			margin: 0 auto;
		}

	}

	.confirmBtnDis {
		background: #DDDDDD;
	}

	.confirmBtn {
		background: #1A1A1A;

	}
</style>